package com.guofen.controller.sjq;

import com.guofen.pojo.SjqSolidliquidProduceElectricity;
import com.guofen.pojo.SjqSolidliquidProduceInspection;
import com.guofen.service.sjq.SjqSolidliquidProduceInspectionService;
import com.guofen.util.result.Result;
import com.guofen.util.result.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


@RequestMapping("/shlj/sjqSolidliquidProduceInspection")
@Controller
@Api(tags = "SjqSolidliquidProduceInspectionController", description = "固液分离设备检查表")
public class SjqSolidliquidProduceInspectionController {
    @Autowired
    private SjqSolidliquidProduceInspectionService sjqSolidliquidProduceInspectionService;

    //保存
    @ApiOperation("添加记录_记录人")
    @RequestMapping(value = "/add_recorder",method = RequestMethod.POST)
    @ResponseBody
    public Result add_recorder(@ApiParam(name="equipment_name",value="设备名称",required=true) @RequestParam String equipment_name,
                               @ApiParam(name="is_normal",value="是否正常",required=true) @RequestParam String is_normal,
                               @ApiParam(name="remarks",value="备注",required=true) @RequestParam String remarks,
                               @ApiParam(name="operator",value="操作人",required=true) @RequestParam String operator){
        if (sjqSolidliquidProduceInspectionService.add(equipment_name,is_normal,remarks,operator))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }

    @ApiOperation("添加记录_检察人")
    @RequestMapping(value = "/add_examiner",method = RequestMethod.POST)
    @ResponseBody
    public Result add_inspector(@ApiParam(name="id",value="id",required=true) @RequestParam String id,
                                @ApiParam(name="Inspector",value="记录人",required=true) @RequestParam String Inspector,
                                @ApiParam(name="remarks",value="备注",required=true) @RequestParam String remarks){

        if (sjqSolidliquidProduceInspectionService.update(id,Inspector,remarks))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }

    @ApiOperation("获取 当日 最新 记录")
    @RequestMapping(value = "/getlast_day",method = RequestMethod.GET)
    @ResponseBody
    public Result getlast_day(){
        return  ResultGenerator.genSuccessResult(sjqSolidliquidProduceInspectionService.getlast_day());
    }

    @ApiOperation("删除记录")
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ResponseBody
    public Result delete(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id) {
        return ResultGenerator.genSuccessResult(sjqSolidliquidProduceInspectionService.delete(id));
    }

    @ApiOperation("修改记录")
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    public Result update(@ApiParam(name="id",value="id",required=true) @RequestParam(required = true) Integer id,
                         @ApiParam(name="date",value="date",required=false) @RequestParam(required = false) String date,
                         @ApiParam(name="equipment_name",value="equipment_name",required=false) @RequestParam(required = false) String equipment_name,
                         @ApiParam(name="is_normal",value="is_normal",required=false) @RequestParam(required = false) String is_normal,
                         @ApiParam(name="remarks",value="remarks",required=false) @RequestParam(required = false) String remarks,
                         @ApiParam(name="operator",value="operator",required=false) @RequestParam(required = false) String operator,
                         @ApiParam(name="inspector",value="inspector",required=false) @RequestParam(required = false) String inspector

    ) {
        SjqSolidliquidProduceInspection record = new SjqSolidliquidProduceInspection();
        record.setId(id);
        record.setDate(date);
        record.setEquipmentName(equipment_name);
        record.setIsNormal(is_normal);
        record.setRemarks(remarks);
        record.setOperator(operator);
        record.setInspector(inspector);

        return ResultGenerator.genSuccessResult(sjqSolidliquidProduceInspectionService.update(record));
    }

    @ApiOperation("查找记录")
    @RequestMapping(value = "/select",method = RequestMethod.POST)
    @ResponseBody
    public Result select(@ApiParam(name="pageSize",value="页容量",required=true) @RequestParam Integer pageSize,
                         @ApiParam(name="currentPage",value="当前页",required=true) @RequestParam Integer currentPage,
                         @ApiParam(name="startTime",value="开始时间(时间戳：毫秒)",required = false) @RequestParam(required = false) Long startTime,
                         @ApiParam(name="endTime",value="截止时间(时间戳：毫秒)", required = false) @RequestParam(required = false) Long endTime) {
        if (startTime == null || endTime == null)
            return ResultGenerator.genSuccessResult(sjqSolidliquidProduceInspectionService.get(pageSize, currentPage));
        else
            return ResultGenerator.genSuccessResult(sjqSolidliquidProduceInspectionService.getByTime(pageSize, currentPage, startTime, endTime));
    }

}
